/*
package com.runfast.waimai.utils.websocket;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.runfast.waimai.dao.model.BaseUser;
import com.runfast.waimai.dao.model.RunfastGoodsSellRecord;
import com.runfast.waimai.dao.model.WaiMaiRunfastAgentaccounts;
import com.runfast.waimai.dao.model.WaiMaiRunfastAgentbusiness;
import com.runfast.waimai.service.BaseUserService;
import com.runfast.waimai.service.WaiMaiRunfastAgentaccountsService;
import com.runfast.waimai.service.WaiMaiRunfastAgentbusinessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

*/
/**
 * 功能说明：websocket处理类, 使用J2EE7的标准
 * @version 1.0
*//*

@Component
@ServerEndpoint("/websocket/{userName}/{userType}/{token}")
public class WebsocketController {
    @Autowired
    private WaiMaiRunfastAgentbusinessService runfastAgentbusinessService;
    @Autowired
    private WaiMaiRunfastAgentaccountsService runfastAgentaccountsService;
    @Autowired
    private BaseUserService baseUserService;
	private static final Logger logger = LoggerFactory.getLogger(WebsocketController.class);

    private Session session;

    public static CopyOnWriteArraySet<WebsocketController> webSockets = new CopyOnWriteArraySet<>();
    //public static Map<String, Session> clients = new ConcurrentHashMap<String, Session>();
    public static Map<String, Map> userSession = new ConcurrentHashMap<String, Map>();
     */
/**
     * 打开连接时触发
     * @param //myWebsocket
     * @param session
     *//*

    @OnOpen
    public void onOpen(Session session, @PathParam("userName")String userName, @PathParam("userType")String userType, @PathParam("token")String token){
        //logger.info("Websocket Start Connecting:" + myWebsocket);
        //System.out.println("进入："+myWebsocket);
        //System.out.println(userName);
        //System.out.println(userType);
        Map<String,String> map=new HashMap<>();
        map.put("userName",userName);
        map.put("userType",userType);
        userSession.put(session.getId(),map);
        this.session = session;
        webSockets.add(this);
        System.out.println("1");
        //clients.put(myWebsocket, session);
    }

     */
/**
     * 收到客户端消息时触发
     * @param myWebsocket
     * @param message
     * @return
     *//*

    @OnMessage
    public String onMessage(@PathParam("myWebsocket") String myWebsocket, String message) {
        System.out.println("2");
        return "Got your message ("+ message +").Thanks !";
    }

    */
/**
     * 异常时触发
     * @param myWebsocket
     * @param throwable
     *//*

    @OnError
    public void onError(@PathParam("myWebsocket") String myWebsocket, Throwable throwable) {
        //logger.info("Websocket Connection Exception:" + myWebsocket);
        //logger.info(throwable.getMessage(), throwable);
        System.out.println("3");
        //clients.remove(myWebsocket);
        webSockets.remove(this);
    }

    */
/**
     * 关闭连接时触发
     * @param //myWebsocket
     *//*

    @OnClose
    public void onClose() {
        //logger.info("Websocket Close Connection:" + myWebsocket);
        System.out.println("4");
        //clients.remove(myWebsocket);
        webSockets.remove(this);
    }

    */
/**
     * 将数据传回客户端
     * 异步的方式
     * @param //myWebsocket
     * @param //message
     *//*

    public  void broadcast(RunfastGoodsSellRecord order) {
        String message= JSONObject.toJSONStringWithDateFormat(order,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue);
        //System.out.println(message);
       // System.out.println("5");
        for (WebsocketController webSocket : webSockets) {

            Map map=userSession.get(webSocket.session.getId());
            if(map.get("userType").equals("1")){
                BaseUser baseUser=baseUserService.checkByUsername(map.get("userName").toString());
                if(baseUser.getId()==1){
                    try {
                        webSocket.session.getBasicRemote().sendText(message);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }else{
                    List<Integer> agentIds=baseUserService.queryAgentIdsByUser(baseUser);
                    if(agentIds.contains(order.getAgentid())){
                        try {
                            webSocket.session.getBasicRemote().sendText(message);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }else if(map.get("userType").equals("2")){
                WaiMaiRunfastAgentaccounts runfastAgentaccounts=runfastAgentaccountsService.findByaccounts(map.get("userName").toString());
                WaiMaiRunfastAgentbusiness runfastAgentbusiness=runfastAgentbusinessService.selectByPrimaryKey(runfastAgentaccounts.getAgentid());//AgentBusiness代理商
                List<Integer> agentIds=runfastAgentbusinessService.findByAgentId(runfastAgentbusiness.getId());//根据上级代理商ID查找代理商id
                if(agentIds.contains(order.getAgentid())){
                    try {
                        webSocket.session.getBasicRemote().sendText(message);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

}
*/
